/*
 * Copyright (C) 2011 Macambira Team
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package com.googlecode.control;

import com.googlecode.entity.Disciplina;
import java.util.LinkedList;
import java.util.List;

/**
 * Classe responsavel por realizar CRUD de disciplinas disponiveis no semestre
 * 
 * @version 0.1 08 Nov 2011
 * @author Tony Silva | tony.silva@dce.ufpb.br
 */
public class DisciplinaOferecidaNoSemestre {
    
    private List <Disciplina> disciplinaOferecida;
    
    public DisciplinaOferecidaNoSemestre() {
        this.disciplinaOferecida = new LinkedList<Disciplina>();
    }
    
    public List getDisciplinaOferecidaNoSemestre() {
        return  this.disciplinaOferecida;
    }
    
    public void setDisciplinaOferecidaNoSemestre(List novaList) {
        this.disciplinaOferecida = novaList;
    }
    
    public void addDisciplinaOferecidaNoSemestre(Disciplina disc) {
        int cont = 0;
        for (Disciplina d: disciplinaOferecida) {
            if (d.getNome().equals(disc.getNome()) && d.getId().equals(disc.getId())) {
               cont++;
            }
        }
        
        if (cont == 0) {
             this.disciplinaOferecida.add(disc);
        }
    }
    
    public void removerPorNomeDisciplinaOferecidaNoSemestre(String nome) {
        disciplinaOferecida.remove(buscarPorNomeDisiciplinaOferecidaNoSemestre(nome));
    }
    
    public void removerPorIDDisciplinaOferecidaNoSemestre(String id) {
        disciplinaOferecida.remove(buscarPorIDDisiciplinaOferecidaNoSemestre(id));
    }
    
    public Disciplina buscarPorNomeDisiciplinaOferecidaNoSemestre(String nome) {
        for (Disciplina d : disciplinaOferecida) {
            if (d.getNome().equals(nome)) {
                return d;
            }
        }
        return null;
    }
    
    public Disciplina buscarPorIDDisiciplinaOferecidaNoSemestre(String id) {
        for (Disciplina d : disciplinaOferecida) {
            if (d.getId().equals(id)) {
                return d;
            }
        }
        return null;
    }
    
    public int getSize() {
        return this.disciplinaOferecida.size();
    }
}
